﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SpreadsheetGear;
using WorkbookDesigner.Addons.SpreadsheetEditor.Model;
using WorkbookDesigner.Annotations;


namespace WorkbookDesigner.Addons.SpreadsheetEditor.UI
{
    public partial class PromptForm : Form, INotifyPropertyChanged
    {
        public PromptForm()
        {
            InitializeComponent();
        }

        public PromptForm(PromptModel pm) : this()
        {
            GetPro(pm);
        }

        //private readonly IRange _row;
        public bool VisiblePrompt
        {
            get { return checkBoxVisible.Checked; }
            private set { checkBoxVisible.Checked = value; }
        }
        public string PromptName
        {
            get { return textBoxName.Text; }
            private set
            {
                textBoxName.Text = value;
                OnPropertyChanged();
            }
        }

        public string Value
        {
            get { return textBoxValue.Text; }
            private set
            {
                textBoxValue.Text = value;
                OnPropertyChanged();
            }
        }

        public string ControlType
        {
            get { return textBoxControlType.Text; }
            private set
            {
                textBoxControlType.Text = value;
                OnPropertyChanged();
            }
        }

        public string HelpMessage
        {
            get
            {
                return textBoxHelpMessage.Text;
            }
            private set
            {
                textBoxHelpMessage.Text = value;
                OnPropertyChanged();
            }
        }

        public string VerifyCode
        {
            get { return textBoxVerifyCode.Text; }
            private set
            {
                textBoxVerifyCode.Text = value;
                OnPropertyChanged();
            }
        }

        public string ComboString
        {
            get { return textBoxComboString.Text; }
            private set
            {
                textBoxComboString.Text = value;
                OnPropertyChanged();
            }
        }

        public string Color
        {
            get { return textBoxColor.Text; }
            private set
            {
                textBoxColor.Text = value;
                OnPropertyChanged();
            }
        }

        public string Picture
        {
            get { return textBoxPicture.Text; }
            private set
            {
                textBoxPicture.Text = value;
                OnPropertyChanged();
            }
        }

        public string VisibleRange
        {
            get { return textBoxVisible.Text; }
            private set
            {
                textBoxVisible.Text = value;
                OnPropertyChanged();
            }
        }

        public string HideInReport
        {
            get { return textBoxHideInReport.Text; }
            private set
            {
                textBoxHideInReport.Text = value;
                OnPropertyChanged();
            }
        }

        public string PromptTabIndex
        {
            get { return textBoxTabIndex.Text; }
            private set
            {
                textBoxTabIndex.Text = value;
                OnPropertyChanged();
            }
        }

        public string CalculatorIndex
        {
            get { return textBoxCalIndex.Text; }
            private set
            {
                textBoxCalIndex.Text = value;
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        public PromptModel GetPrompt()
        {
            return new PromptModel()
            {
                Name = PromptName,
                Value = Value,
                ControlType = ControlType,
                HelpMessage = HelpMessage,
                VerifyCode = VerifyCode,
                ComboString = ComboString,
                Color = Color,
                Picture = Picture,
                VisibleRange = VisibleRange,
                HideInReport = HideInReport,
                TabIndex = PromptTabIndex,
                CalculatorIndex = CalculatorIndex,
                VisiblePrompt = VisiblePrompt,
            };
        }
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void GetPro(PromptModel pm)
        {
            PromptName = pm.Name;
            Value = pm.Value;
            ControlType = pm.ControlType;
            HelpMessage = pm.HelpMessage;
            VerifyCode = pm.VerifyCode;
            ComboString = pm.ComboString;
            Color = pm.Color;
            Picture = pm.Picture;
            VisibleRange = pm.VisibleRange;
            HideInReport = pm.HideInReport;
            PromptTabIndex = pm.TabIndex;
            CalculatorIndex = pm.CalculatorIndex;
            VisiblePrompt = pm.VisiblePrompt;
        }

        public void SyncPrompt(PromptModel pm)
        {
            pm.Name = PromptName;
            pm.Value = Value;
            pm.ControlType = ControlType;
            pm.HelpMessage = HelpMessage;
            pm.VerifyCode = VerifyCode;
            pm.ComboString = ComboString;
            pm.Color = Color;
            pm.Picture = Picture;
            pm.VisibleRange = VisibleRange;
            pm.HideInReport = HideInReport;
            pm.TabIndex = PromptTabIndex;
            pm.CalculatorIndex = CalculatorIndex;
            pm.VisiblePrompt = VisiblePrompt;
        }
    }
}
